<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>逛水果店</title>
    <style>
        tr {
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app">
        <h3>欢迎光临_vue开发的收银系统水果店</h3>
        <table border="1">
            <tr>
                <td>苹果10￥/斤, 折扣<8折>
                </td>
            </tr>
            <tr>
                <td>请输入你要购买的斤数：
                    <input type="number" v-model="appleWeight">斤
                </td>
            </tr>
            <tr>
                <td>
                    <button @click="calPrice">结账买单~</button>
                </td>
            </tr>
            <tr>
                <td>
                    结账单: 总价: {{ totalPrice }}￥元 折后价: {{ discountPrice }}￥元 省了: {{ totalPrice - discountPrice }}￥元
                </td>
            </tr>
        </table>
    </div>

    <script src="../vue.js"></script>
    <script>
        let app = new Vue({
            el: '#app',
            data: {
                appleWeight: 0
            },
            methods: {
                calPrice() {
                    alert(`结账成功，共计 ${this.totalPrice} 元`);
                }
            },
            computed: {
                totalPrice() {
                    return 10 * this.appleWeight;
                },
                discountPrice() {
                    return this.totalPrice * 0.8;
                }
            }
        })
    </script>
</body>

</html>